package com.fick.tags;

/**
 */
import java.io.IOException;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.fick.hibernate.dao.SiteInfoDAO;
import com.fick.hibernate.model.SiteInfo;

@SuppressWarnings("serial")
public class SiteInfoTag extends TagSupport {
	private static Log log = LogFactory.getLog(SiteInfoTag.class);

	public static Log getLog() {
		return log;
	}

	public static void setLog(Log log) {
		SiteInfoTag.log = log;
	}

	private String author = "";
	private String author_tel = "";
	private String author_mobile = "";
	private String author_email = "";
	private String author_blog = "";
	private String site_copyright = "";

	private String site_version = "";

	private String operator = " ";

	@Override
	public int doStartTag() throws JspException {

		SiteInfoDAO dao = new SiteInfoDAO();
		@SuppressWarnings("unchecked")
		List<SiteInfo> list = dao.findBySql(SiteInfo.class, "");
		JspWriter out = pageContext.getOut();
		String ret = "";
		if (list != null && list.size() > 0) {
			SiteInfo siteinfo = list.get(0);
			StringBuffer sb = new StringBuffer("");
			if (!"".equals(author)) {
				sb.append(siteinfo.getAuthor());
				sb.append(operator);
			}
			if (!"".equals(author_tel)) {
				sb.append(siteinfo.getAuthor_tel());
				sb.append(operator);
			}
			if (!"".equals(author_mobile)) {
				sb.append(siteinfo.getAuthor_mobile());
				sb.append(operator);
			}
			if (!"".equals(author_email)) {
				sb.append(siteinfo.getAuthor_email());
				sb.append(operator);
			}
			if (!"".equals(author_blog)) {
				sb.append(siteinfo.getAuthor_blog());
				sb.append(operator);
			}
			if (!"".equals(site_copyright)) {
				sb.append(siteinfo.getSite_copyright());
				sb.append(operator);
			}
			if (!"".equals(site_version)) {
				sb.append(siteinfo.getSite_version());
				sb.append(operator);
			}
			ret = sb.toString();
		} else {
			ret = "null";
		}
		try {
			out.println(ret);
			out.flush();
		} catch (IOException e) {
		}

		return SKIP_BODY;
	}

	public String getAuthor() {
		return author;
	}

	public String getAuthor_blog() {
		return author_blog;
	}

	public String getAuthor_email() {
		return author_email;
	}

	public String getAuthor_mobile() {
		return author_mobile;
	}

	public String getAuthor_tel() {
		return author_tel;
	}

	public String getOperator() {
		return operator;
	}

	public String getSite_copyright() {
		return site_copyright;
	}

	public String getSite_version() {
		return site_version;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public void setAuthor_blog(String author_blog) {
		this.author_blog = author_blog;
	}

	public void setAuthor_email(String author_email) {
		this.author_email = author_email;
	}

	public void setAuthor_mobile(String author_mobile) {
		this.author_mobile = author_mobile;
	}

	public void setAuthor_tel(String author_tel) {
		this.author_tel = author_tel;
	}

	public void setOperator(String operator) {
		this.operator = operator;
	}

	public void setSite_copyright(String site_copyright) {
		this.site_copyright = site_copyright;
	}

	public void setSite_version(String site_version) {
		this.site_version = site_version;
	}

}
